/*
 * $Id: IPTDSSystemInfo.java,v 1.4 2009/04/03 15:20:27 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.processor.iptds;

import com.ge.healthcare.autosc.common.exceptions.GSCCUtilException;
import com.ge.healthcare.autosc.common.pojo.sysInfo.SystemDetails;
import com.ge.healthcare.autosc.common.pojo.sysInfo.SystemInfo;
import com.ge.healthcare.autosc.processor.iptds.transaction.IPTDSFTPCommand;
import com.ge.healthcare.autosc.processor.iptds.worker.HandshakeResult;
/**
 * 
 * @author 212042946
 *
 */
public class IPTDSSystemInfo extends SystemInfo {
   
    /* socket holder to the remote system */
	private IPTDSSocketHandler socketHandler = null;
    /* FTP Connection holder to the remote system */
	private IPTDSFTPCommand ftpCommand = null;
	/* Handshake information */
	private HandshakeResult handshakeResult = null;
    
	/**
	 * Constructor
	 */
    protected IPTDSSystemInfo() {
    	super();
    }
    
    /**
     * Constructor
     * @param systemDetails
     * @throws GSCCUtilException
     */
    public IPTDSSystemInfo(SystemDetails systemDetails) 
    	throws GSCCUtilException {
   		super(systemDetails);
    }
    
    /**
     * Set HandshakeResult object
     * @param result - HandshakeResult
     */
    public void setHandshakeResult(HandshakeResult result) {
    	this.handshakeResult = result;
    }
    
    /**
     * Determine if system request in urgent mode
     * @return true/false
     */
    public boolean isUrgentMode() {
    	boolean status = false;
    	if(handshakeResult != null) {
    		status = (handshakeResult.isUrgentMode());
    	}
    	return status;
    }
    
    /**
     * Get USN from handshaking
     * @return
     */
    public String getScanUsn() {
    	//return scanUsn;
    	String scanUsn = null;
    	if(handshakeResult != null) {
    		scanUsn = handshakeResult.getScanUsn();
    	}
    	return scanUsn;
    }
    
    /**
     * Get site name from handshaking
     * @return
     */
    public String getScanSiteName() {
    	String scanSiteName = null;
    	if(handshakeResult != null) {
    		scanSiteName = handshakeResult.getScanSiteName();
    	}
    	return scanSiteName;
    }
    
	/**
	 * get dispatch argument 
	 * @param index argument number starting from 0
	 * @return
	 */
	public String getDispatchArg(int index) {
		String value = null;
		if(handshakeResult != null) {
			value = handshakeResult.getDispatchArg(index);
		}
		return value;
	}
	
	/**
	 * Get the remote file path from dispatch argument
	 * @return remote file path
	 */
	public String getRemoteFilePathFromArg() {
		return getDispatchArg(1);
	}
	
	/**
	 * Set socket handler to the remote system
	 * @param socketHandler
	 */
	public void setSocketHandler(IPTDSSocketHandler socketHandler) {
		this.socketHandler = socketHandler;
	}
	
	/**
	 * Get socket handler to the remote system
	 * @return
	 */
	public IPTDSSocketHandler getSocketHandler() {
		return socketHandler;
	}
	
	/**
	 * Set IPTDSFTPcommand object to the remote system
	 * @param ftpCommand
	 */
	public void setFTPCommand(IPTDSFTPCommand ftpCommand) {
		this.ftpCommand = ftpCommand;
	}
	
	/**
	 * Get IPTDSFTPCommand object to the remote system
	 * @return
	 */
	public IPTDSFTPCommand getFTPCommand() {
		return this.ftpCommand;
	}
	
	/**
	 * Determine if the system is a simulator
	 * @return true/false
	 */
	public boolean isSimulator() {
		if(handshakeResult != null) {
			return handshakeResult.isSimulator();
		}
		return false;
	}
	
	/**
	 * Use the connecting IP address for other connectivity
	 * activities. This is for simulation when the connecting
	 * IP address is different from the IP address in the 
	 * GSCC
	 * @return	true(Successful)/false(Failure)
	 */
	public boolean turnOnSimulator() {
		boolean status = true;
		if(handshakeResult != null) {
			handshakeResult.setSimulator(true);
			if(socketHandler != null) {
				ipAddress = socketHandler.getHostAddress();
			}
		} else {
			status = false;
		}
		return status;
	}
	
	public String toString() {
		StringBuffer msg = new StringBuffer();
		msg.append(super.toString());
		if(handshakeResult != null) {
			msg.append("Dispatch Service: ").append(handshakeResult.getDispatchService()).append("\n");
			msg.append("Dispatch Arg0: ").append(handshakeResult.getDispatchArg(0)).append("\n");
			msg.append("Dispatch Arg1: ").append(handshakeResult.getDispatchArg(1)).append("\n");
		}
		return msg.toString();
	}
}
